package de.gwtprime.client.widgets;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;

/**
 * Show a youtube video with a gwt widget.
 */
public class YouTubeWidget extends Widget{
		
	
		public YouTubeWidget(String id){
			this(id, 640,360);
		}
		
		public YouTubeWidget(){
			this("SVTMCkpFkJI", 640,360);
			
		}
		public YouTubeWidget(String id, int width, int height) {
			
			
			String url = "https://www.youtube.com/v/"+id+"?version=3&showinfo=0";
			Element object = Document.get().createElement("object");
			
			object.setAttribute("width", String.valueOf(width));
			object.setAttribute("height", String.valueOf(height));
			
			Element param = Document.get().createElement("param");
			param.setAttribute("movie", url);
			object.appendChild(param);
			
			
			Element param2 = Document.get().createElement("param");
			param2.setAttribute("name", "allowFullScreen");
			param2.setAttribute("value", "true");
			object.appendChild(param2);
			
			Element param3 = Document.get().createElement("param");
			param3.setAttribute("name", "allowScriptAccess");
			param3.setAttribute("value", "always");
			object.appendChild(param3);
			
			Element param4 = Document.get().createElement("embed");
			param4.setAttribute("src", url);
			param4.setAttribute("type", "application/x-shockwave-flash");
			param4.setAttribute("allowfullscreen", "true");
			param4.setAttribute("allowScriptAccess", "always");
			param4.setAttribute("width", String.valueOf(width));
			param4.setAttribute("height", String.valueOf(height));
			object.appendChild(param4);
			
			
			setElement(object);
		}
	}